package com.example.fridaykt.utils

import cn.hutool.crypto.symmetric.SymmetricAlgorithm
import cn.hutool.crypto.symmetric.SymmetricCrypto
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component
import java.nio.charset.StandardCharsets

@Component
class CryptoUtil {
    @Value("\${friday.privateKey}")
    lateinit var privateKey: String

    fun encrypt(content: String?): String {
        println(privateKey)
        val aes = SymmetricCrypto(SymmetricAlgorithm.AES, privateKey.toByteArray(StandardCharsets.UTF_8))
        return aes.encryptHex(content)
    }

    fun decrypt(content: String?): String {
        val aes = SymmetricCrypto(SymmetricAlgorithm.AES, privateKey.toByteArray(StandardCharsets.UTF_8))
        return aes.decryptStr(content)
    }
}
